import {Component, Input, OnInit} from '@angular/core';
import {GetRTDataByKKSCodesService} from '../../../services/get-rtdata-by-kkscodes.service'

@Component({
  selector: 'app-table-device-parameters-left',
  templateUrl: './table-device-parameters-left.component.html',
  styleUrls: ['./table-device-parameters-left.component.css']
})
export class TableDeviceParametersLeftComponent implements OnInit {
  public data: any[]=[];

  constructor(
    private getKksRes:GetRTDataByKKSCodesService
  ) { }

  @Input() stationName:string
  @Input() id:string
  @Input() totalKks:string

  public toColor(code:number):string{
    let c='gray';
    switch (code){
      case 1:c='#0038FF';break;
      case 2:c='#21A221';break;
      case 3:c='#00CCC3';break;
      case 4:c='#E70000';break;
      case 5:c='#FF84CE';break;
      case 6:c='#B500A2';break;
      case 7:c='#3A383A';break;
      case 8:c='#EFEB00';break;
    }
    return c;
  }
  public styles:object={fill:'gray'};
  ngOnInit() {
    // this.data=[]
    for(let i=0;i<10;i++){
      this.data.push(0);
    }
    // console.log(this.data)
    this.getKksRes.getRestKksByComponent('deviceParams')
      .subscribe(res=>{
        let kksString=res.map(value=>{
          return this.totalKks+value;
        })
        this.getKksRes.getKKsDataSnap(kksString)
          .subscribe(res=>{
            let datas=[];
            kksString.forEach(value=>{
              res.RTDataSets.forEach(val=>{
                if (value===val.kksCode){
                  // if(val.RTDataValues[0].Value)
                  datas.push(val.RTDataValues[0].Value)
                }
              })
            })
            if(datas.length===this.data.length){
              this.data=datas;
              this.styles['fill']=this.toColor(this.data[0]);
            }
          })
      })
  }

}
